<?php

/*
File: confignew.php (originally configuration.php)
Version: 1.0
Date created: 26-07-2008
Last Edited : 26-07-2008
Author: Craig G Smith<craig@joomla-host.co.za
*/


defined( 'JOSCOM_VERSION' ) or die( 'Direct Access to this location is not allowed.' );

if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      tep_db_connect() or die('Unable to connect to database server!');
    }
    global $category_links, $languages_id, $cPath, $cPath_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    require(DIR_WS_COMPONENT . 'includes/application_top.php');
  }

//set our variables that are used!
$grpid = isset($_REQUEST['gID'])?$_REQUEST['gID']:1;
$action = isset($_REQUEST['action'])?$_REQUEST['action']:'';

switch ($action) {
  case "save":
    $url = tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $grpid . '&msg=' . TEXT_UPDATE_COMPLETE);
      foreach ($_POST['configuration'] as $key=>$value){
      //$value = tep_db_prepare_input($value);
        $database->setQuery("Update #__osc_configuration set configuration_value = '$value' where configuration_key = '$key'");
        $database->query();

      }
   if(isset($_POST['STORE_COUNTRY'])){
       $database->setQuery("Update #__osc_configuration set configuration_value = '{$_POST['STORE_COUNTRY']}' where configuration_key = 'STORE_COUNTRY'");
      $database->query();
}
    tep_redirect($url);
  break;

  case "show":
  default:

//get our heading
    $database->setQuery("Select configuration_group_title from #__osc_configuration_group where configuration_group_id = '$grpid' and visible = 1");
    $headtext = $database->loadResult();
      if(!$headtext) {
        $headtext = 'My Store';
        $grpid = 1;
      }

//get all the options for the specific option:
    $database->setQuery("Select * from #__osc_configuration where configuration_group_id = '$grpid' order by sort_order asc");
    $options = $database->loadObjectList();
//ok lets display:::
?>


<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_COMPONENT ?>includes/stylesheet.css">
<script language="javascript" src="<?php echo DIR_WS_COMPONENT ?>includes/general.js"></script>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo $headtext; ?></td>
            <td class="pageHeading" align="right"></td>
          </tr>
        </table>
        
    <table class="adminlist" cellspacing="1">
    <thead>
              <tr class="dataTableHeadingRow">
                <th class="dataTableHeadingContent"><?php echo TABLE_HEADING_CONFIGURATION_TITLE; ?></th>
                <th class="dataTableHeadingContent"><?php echo TABLE_HEADING_CONFIGURATION_VALUE; ?></th>
                <th class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_DESCRIPTION; ?></th>
              </tr>
              </thead>
           <?php
          echo    tep_draw_form('configuration', tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $grpid  . '&action=save'), "POST");

$row = 0;
foreach($options as $option){
     ?><tr class="dataTableRow<?php echo $row;?>" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">
      <td valign="top"><strong><?php echo $option->configuration_title;?>:</strong></td>
      <td valign="top"><?php
      //box here with the either radio / dropdown etc:::
       if ($option->set_function) {
        eval('$value_field = new_' . $option->set_function . '"' . htmlspecialchars($option->configuration_value) . '","' . $option->configuration_key . '");');
      } else {
        $value_field = tep_draw_input_field("configuration[{$option->configuration_key}]",  $option->configuration_value);
      }
      echo $value_field;
      ?></td>
      <td valign="top"><?php echo $option->configuration_description;?></td>
      </tr>
      <?php    
      $row = 1 - $row;
    }
    ?>
    <tr><td></td><td><?php echo tep_image_submit('button_update.gif', IMAGE_UPDATE);?></td><td></td></tr>
     </tr>
        </table></form></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->

    
    <?php

break;

}


  require(DIR_WS_INCLUDES . 'application_bottom.php');
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
